<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis 消息队列实现指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .mermaid {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <i class="fas fa-layer-group mr-4"></i>Redis 消息队列
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">构建高性能、可靠的分布式消息系统</p>
                <div class="flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-rocket mr-2"></i>高性能
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-shield-alt mr-2"></i>可靠性
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                        <i class="fas fa-expand-arrows-alt mr-2"></i>可扩展
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <h2 class="text-3xl font-bold mb-6 text-gradient">
                <i class="fas fa-info-circle mr-3"></i>什么是 Redis 消息队列？
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                Redis 作为一个高性能的内存数据库，不仅可以用作缓存，还可以实现强大的消息队列功能。通过 Redis 的列表（List）、发布订阅（Pub/Sub）和流（Stream）等数据结构，我们可以构建出满足不同场景需求的消息队列系统。它具有低延迟、高吞吐量的特点，特别适合实时性要求高的应用场景。
            </p>
        </section>

        <!-- Implementation Methods -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-code mr-3 text-gradient"></i>实现方式
            </h2>
            <div class="grid md:grid-cols-3 gap-6">
                <!-- List -->
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl mb-4 feature-icon">
                        <i class="fas fa-list"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">List 列表</h3>
                    <p class="text-gray-600 mb-4">使用 LPUSH/RPOP 或 RPUSH/LPOP 实现简单的先进先出队列</p>
                    <ul class="space-y-2 text-sm text-gray-500">
                        <li><i class="fas fa-check text-green-500 mr-2"></i>实现简单</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>支持阻塞读取</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>消息持久化</li>
                    </ul>
                </div>

                <!-- Pub/Sub -->
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl mb-4 feature-icon">
                        <i class="fas fa-broadcast-tower"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">Pub/Sub 发布订阅</h3>
                    <p class="text-gray-600 mb-4">实现一对多的消息广播模式，适合实时通知场景</p>
                    <ul class="space-y-2 text-sm text-gray-500">
                        <li><i class="fas fa-check text-green-500 mr-2"></i>实时性高</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>支持模式匹配</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>多订阅者</li>
                    </ul>
                </div>

                <!-- Stream -->
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <div class="text-4xl mb-4 feature-icon">
                        <i class="fas fa-stream"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">Stream 流</h3>
                    <p class="text-gray-600 mb-4">Redis 5.0+ 新特性，专为消息队列设计的数据结构</p>
                    <ul class="space-y-2 text-sm text-gray-500">
                        <li><i class="fas fa-check text-green-500 mr-2"></i>消费者组</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>消息确认</li>
                        <li><i class="fas fa-check text-green-500 mr-2"></i>消息重试</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Architecture Diagram -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center">
                <i class="fas fa-project-diagram mr-3 text-gradient"></i>系统架构
            </h2>
            <div class="mermaid">
                graph LR
                    A[生产者] -->|LPUSH| B[Redis List]
                    B -->|BRPOP| C[消费者1]
                    B -->|BRPOP| D[消费者2]
                    B -->|BRPOP| E[消费者3]
                    
                    F[发布者] -->|PUBLISH| G[Redis Pub/Sub]
                    G -->|SUBSCRIBE| H[订阅者1]
                    G -->|SUBSCRIBE| I[订阅者2]
                    
                    J[Producer] -->|XADD| K[Redis Stream]
                    K -->|XREADGROUP| L[Consumer Group]
                    L --> M[Consumer A]
                    L --> N[Consumer B]
                    
                    style A fill:#667eea,stroke:#fff,color:#fff
                    style F fill:#667eea,stroke:#fff,color:#fff
                    style J fill:#667eea,stroke:#fff,color:#fff
                    style B fill:#764ba2,stroke:#fff,color:#fff
                    style G fill:#764ba2,stroke:#fff,color:#fff
                    style K fill:#764ba2,stroke:#fff,color:#fff
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-12">
            <h2 class="text-3xl font-bold mb-8 text-center">
                <i class="fas fa-lightbulb mr-3 text-gradient"></i>最佳实践
            </h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-purple-50 to-indigo-50 rounded-xl p-6">
                    <h3 class="text-xl font-bold mb-4 text-purple-800">
                        <i class="fas fa-shield-alt mr-2"></i>可靠性保障
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li><i class="fas fa-arrow-right text-purple-600 mr-2"></i>使用持久化机制（RDB/AOF）防止数据丢失</li>
                        <li><i class="fas fa-arrow-right text-purple-600 mr-2"></i>实现消息确认机制，确保消息被正确处理</li>
                        <li><i class="fas fa-arrow-right text-purple-600 mr-2"></i>设置合理的超时和重试策略</li>
                        <li><i class="fas fa-arrow-right text-purple-600 mr-2"></i>监控队列长度，防止内存溢出</li>
                    </ul>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-cyan-50 rounded-xl p-6">
                    <h3 class="text-xl font-bold mb-4 text-blue-800">
                        <i class="fas fa-tachometer-alt mr-2"></i>性能优化
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li><i class="fas fa-arrow-right text-blue-600 mr-2"></i>使用批量操作减少网络往返</li>
                        <li><i class="fas fa-arrow-right text-blue-600 mr-2"></i>合理设置消息大小，避免大消息阻塞</li>
                        <li><i class="fas fa-arrow-right text-blue-600 mr-2"></i>使用连接池管理 Redis 连接</li>
                        <li><i class="fas fa-arrow-right text-blue-600 mr-2"></i>根据业务需求选择合适的数据结构</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Use Cases -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center">
                <i class="fas fa-briefcase mr-3 text-gradient"></i>应用场景
            </h2>
            <div class="grid md:grid-cols-4 gap-4">
                <div class="text-center p-4 hover:bg-purple-50 rounded-lg transition-colors">
                    <i class="fas fa-tasks text-4xl text-purple-600 mb-3"></i>
                    <h4 class="font-semibold">异步任务处理</h4>
                </div>
                <div class="text-center p-4 hover:bg-blue-50 rounded-lg transition-colors">
                    <i class="fas fa-bell text-4xl text-blue-600 mb-3"></i>
                    <h4 class="font-semibold">实时通知推送</h4>
                </div>
                <div class="text-center p-4 hover:bg-green-50 rounded-lg transition-colors">
                    <i class="fas fa-chart-line text-4xl text-green-600 mb-3"></i>
                    <h4 class="font-semibold">日志收集分析</h4>
                </div>
                <div class="text-center p-4 hover:bg-orange-50 rounded-lg transition-colors">
                    <i class="fas fa-sync text-4xl text-orange-600 mb-3"></i>
                    <h4 class="font-semibold">系统解耦</h4>
                </div>
            </div>
        </section>

        <!-- Call to Action -->
        <section class="text-center py-12">
            <h2 class="text-3xl font-bold mb-6">开始使用 Redis 消息队列</h2>
            <p class="text-lg text-gray-600 mb-8">立即构建高性能、可扩展的消息系统</p>
            <a href="https://www.yuque.com/diantostring/qiwsg9/qctvfp?singleDoc#" 
               target="_blank" 
               class="inline-flex items-center px-8 py-4 bg-gradient-to-r from-purple-600 to-indigo-600 text-white font-semibold rounded-full hover:shadow-lg transform hover:scale-105 transition-all">
                <i class="fas fa-book-open mr-3"></i>
                查看完整文档